﻿using System;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Xml.Linq;
using System.Xml;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using Styx.Common;

namespace CommunicationBuddy
{
    class Updater
    {

        //Firstly, I've to import following dll: "SharpSvn.dll".

        private static string Name = "CommunicationBuddy";

        public static void CheckAndStartSVN()
        {

            Logging.Write("[{0}] Checking for updates...", Name);

            using (SvnClient client = new SvnClient())
            {

                SvnInfoEventArgs info;
                Uri repos = new Uri("http://halfbax.googlecode.com/svn/CommunicationBuddy/");
                cr_path = string.Format(@"{0}\Plugins\CommunicationBuddy\", Application.StartupPath);

                client.GetInfo(cr_path, out info_cr); //current revision
                client.GetInfo(repos, out info_lr); //lastet revision

                if (info_lr > info_cr)
                {

                    Logging.Write("[{0}] New version available.", Name);
                    client.Update(cr_path);

                }
                else
                {

                    Logging.Write("[{0}] is up to date now!", Name);
                }
            }
        }
    }
}
